<template>
  <div class="login">
    <div class="header" style="display: none">
      <div class="nav">
        <router-link to="/">
          <img
              alt="LOGO"
              class="logo"
              src="../../assets/images/login/login-logo.png"
          >
        </router-link>
      </div>
    </div>
    <div class="login-container">
      <svg-icon icon-class="login_left" class="login_panle_left"></svg-icon>
      <div class="login-container-f">
        <el-form
            ref="loginForm"
            :model="loginForm"
            :rules="loginRules"
            auto-complete="on"
            class="login-form"
            label-position="left">
          <div class="content">
            <div class="main">
              <h3>注册账号</h3>
              <el-form-item prop="email">
                <el-input
                    v-model.trim="loginForm.email"
                    auto-complete="on"
                    name="email"
                    placeholder="输入邮箱"
                    type="text"/>
              </el-form-item>
              <div class="input_code">
                <el-form-item prop="code">
                  <el-input
                      v-model.trim="loginForm.code"
                      class="main_code_input"
                      name="code"
                      placeholder="输入验证码"
                      type="text"/>
                </el-form-item>
                <el-button :disabled="disabled" class="code_btn" @click="sendEmail()">
                  {{ text }}
                </el-button>
              </div>
              <el-form-item prop="pwd">
                <span class="svg-container">
                  <svg-icon icon-class="lock-custom"/>
                </span>
                <el-input
                    v-model.trim="loginForm.pwd"
                    :type="pwdType"
                    auto-complete="on"
                    name="password"
                    placeholder="请输入密码"
                />
                <span
                    class="show-pwd"
                    @click="showPwd"
                >
                  <svg-icon :icon-class="pwdType === 'password' ? 'eye' : 'eye-open'"/>
                </span>
              </el-form-item>
              <el-form-item prop="checkPwd">
                <span class="svg-container">
                  <svg-icon icon-class="lock-custom"/>
                </span>
                <el-input
                    v-model.trim="loginForm.checkPwd"
                    :type="pwdType1"
                    auto-complete="on"
                    name="password"
                    placeholder="请再次输入密码"
                />
                <span
                    class="show-pwd"
                    @click="showPwd1"
                >
                  <svg-icon :icon-class="pwdType1 === 'password' ? 'eye' : 'eye-open'"/>
                </span>
              </el-form-item>
              <el-form-item prop="shopName">
                <el-input
                    v-model.trim="loginForm.shopName"
                    auto-complete="on"
                    name="shopName"
                    placeholder="店铺名称"/>
              </el-form-item>
<!--              <div class="buttom_content">-->
<!--                &lt;!&ndash; `checked` 为 true 或 false &ndash;&gt;-->
<!--                <el-checkbox v-model="checked" class="check">我接受 <span class="container_title" type="text" @click="openTerms = true">《服务条款》、</span>-->
<!--                 <span class="container_title" type="text" @click="openAgreement = true">《使用协议》</span >和 <span class="container_title" type="text" @click="openPrivacy = true">《隐私政策》</span></el-checkbox>-->
<!--              </div>-->
              <el-form-item>
                <el-button
                    :loading="loading"
                    style="width:100%;"
                    type="primary"
                    @click.native.prevent="handleRegister">
                  注册
                </el-button>
              </el-form-item>
            </div>
          </div>
          <div class="buttom">
            <a class="buttom_title" href="">已有账号？去登录</a>
          </div>
        </el-form>
      </div>
    </div>
    <!-- 服务条款 -->
    <el-dialog
  title="《服务条款》"
  :visible.sync="openTerms"
  width="30%"
  center>
  <span>服务条款</span>
  <span slot="footer" class="dialog-footer">
    <el-button @click="openTerms = false">取 消</el-button>
    <el-button type="primary" @click="openTerms = false">确 定</el-button>
  </span>
</el-dialog>
<!-- 使用协议 -->
    <el-dialog
  title="《使用协议》"
  :visible.sync="openAgreement"
  width="30%"
  center>
  <span>使用协议</span>
  <span slot="footer" class="dialog-footer">
    <el-button @click="openAgreement = false">取 消</el-button>
    <el-button type="primary" @click="openAgreement = false">确 定</el-button>
  </span>
</el-dialog>
<!-- 隐私政策 -->
    <el-dialog
  title="《隐私政策》"
  :visible.sync="openPrivacy"
  width="30%"
  center>
  <span>隐私政策</span>
  <span slot="footer" class="dialog-footer">
    <el-button @click="openPrivacy = false">取 消</el-button>
    <el-button type="primary" @click="openPrivacy = false">确 定</el-button>
  </span>
</el-dialog>
    <footer class="footer">
      <div class="service-intro">
        <div class="friend-link">
          <div class="friend-link-item">
            <ul>
            </ul>
          </div>
        </div>
      </div>
    </footer>
  </div>
</template>
<script>
import md5 from 'js-md5';
import {register, sendEmail} from '@/api/system';

export default {
    name: 'register',
    data () {
        var validatePass = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请再次输入密码'));
            } else if (value !== this.loginForm.pwd) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        };
        return {
            openTerms: false,
            openAgreement: false,
            openPrivacy: false,
            // btn_disabled: true,
            disabled: false,
            second: 120,
            time: 0,
            loginForm: {
                userName: '',
                code: '',
                email: '',
                pwd: '',
                checkPwd: '',
                shopName: ''
            },
            loginRules: {
                email: [
                    {required: true, message: '请输入邮箱', trigger: 'blur'},
                    { type: 'email', message: '邮箱格式不正确', trigger: ['blur', 'change'] }
                ],
                code: [{required: true, message: '请输入验证码', trigger: 'blur'}],
                pwd: [
                    {required: true, message: '请输入密码', trigger: 'blur'},
                    // eslint-disable-next-line standard/object-curly-even-spacing
                    {type: 'string', pattern: /^(?![A-Za-z]+$)(?![A-Z\d]+$)\S{8,}$/, message: '密码最少8位,并且至少包含1个字母和1个数字', trigger: 'blur' }

                ],
                checkPwd: [
                    {required: true, message: '请再次输入密码', trigger: 'blur'},
                    // eslint-disable-next-line standard/object-curly-even-spacing
                    {type: 'string', pattern: /^(?![A-Za-z]+$)(?![A-Z\d]+$)\S{8,}$/, message: '密码最少8位,并且至少包含1个字母和1个数字', trigger: 'blur' },
                    {validator: validatePass, trigger: 'blur'}
                ],
                shopName: [
                    {required: true, message: '请输入店铺名', trigger: 'blur'},
                    {type: 'string', pattern: /^[a-zA-Z\d]+$/, message: '店铺名只支持英文或数字', trigger: 'blur'}
                ]
            },
            loading: false,
            pwdType: 'password',
            pwdType1: 'password',
            redirect: undefined
        };
    },
    computed: {
        text () {
            return this.time > 0 ? this.time + 's再获取' : '获取验证码';
        }
    },
    methods: {
        showPwd () {
            if (this.pwdType === 'password') {
                this.pwdType = '';
            } else {
                this.pwdType = 'password';
            }
        },
        showPwd1 () {
            if (this.pwdType1 === 'password') {
                this.pwdType1 = '';
            } else {
                this.pwdType1 = 'password';
            }
        },
        // 注册按钮点击事件
        handleRegister () {
            this.$refs.loginForm.validate(valid => {
                if (valid) {
                    let params = {
                        userName: this.loginForm.userName,
                        code: this.loginForm.code,
                        email: this.loginForm.email,
                        pwd: md5(this.loginForm.pwd),
                        shopName: this.loginForm.shopName
                    };
                    this.loading = false;
                    register(params).then((res) => {
                        this.$message.success('注册成功');
                        this.loading = false;
                        this.$router.push({path: 'login'});
                    }).catch(() => {
                        this.loading = false;
                    });
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        // 获取验证码点击事件
        sendEmail () {
            var flag = this.checkEmail();
            if (flag) {
                let params = {
                    email: this.loginForm.email,
                    sendType: 'REGISTER_ACCOUNT'
                };
                // 验证码接口请求
                sendEmail(params).then((res) => {
                    this.loading = false;
                }).catch(() => {
                    this.loading = false;
                });
            }
        },
        // 邮箱格式验证
        checkEmail () {
            var regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if (!regEmail.test(this.loginForm.email)) {
                // this.$message({
                //     message: '邮箱格式不正确',
                //     type: 'error'
                // });
                return false;
            } else {
                this.disabled = true;
                this.run();
            }
            return true;
        },
        run () {
            this.time = this.second;
            this.timer();
        },
        stop () {
            this.time = 0;
            this.disabled = false;
        },
        timer () {
            if (this.time > 0) {
                this.time--;
                setTimeout(this.timer, 1000);
            } else {
                this.disabled = false;
            }
        }
    }
};
</script>
<style rel="stylesheet/scss" lang="scss">
$bg: #2d3a4b;
$light_gray: #fff;

.login{
  background-image: url("../../assets/images/login_background.jpg");
  margin: 0;
  padding: 0;
  background-size: cover;
  width: 100%;
  height: 100vh;
  min-height: 690px;
  position: relative;
}

/* reset element-ui css */
.login-container {
  position: absolute;
  top: 3vh;
  left: 2vw;
  width: 96vw;
  height: 94vh;
  background-color: #fffc;
  backdrop-filter: blur(5px);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  .login_panle_left{
    width: 40%;
    height: 60%;
    float: left;
  }
  .login-container-f {
    width: 500px;
    background-color: #fff;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 2px 3px 7px #0003;
    background-image: linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.96) 0%,
            rgba(245, 245, 245, 0.96) 100%
    );
  }
  .el-form {
    width: 460px;
    border-radius: 10px;
    float: right;
    max-width: 100%;
  }
  .el-input {
    display: inline-block;
    height: 42px;
    width: 85%;
    input {
      box-sizing: border-box;
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #000;
      height: 42px;
      line-height: normal;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
        -webkit-text-fill-color: #000 !important;
      }
    }
  }
  .input_code {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  .main_code_input {
    width: 240px;
    height: 42px;
  }

  .code_btn {
    width: 50%;
    height: 44px;
    border: none;
    margin-left: 10px;
  }

  .check {
    margin-bottom: 10px;
    font-size: 12px;
  }

  .buttom_btn{
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
  .button{
    font-size: 14px;
    margin-right: 20px;
  }
  .button_btn{
    font-size: 14px;
    margin-left: 20px;
  }
  .el-form-item {
    border: 1px solid rgb(220, 223, 230);
    background: $light_gray;
    border-radius: 5px;
    color: #454545;
    &.foot-link {
      background: transparent;
      p {
        text-align: right;
        margin: 0;
        a {
          color: #1c73e7;
          &:first-child {
            margin-right: 10px;
          }
        }
      }
    }
  }
}
.contact-jx {
  .el-tabs {
    width: 320px;
    .el-tabs__nav {
      font-size: 16px;
      .el-tabs__item {
        height: auto;
        line-height: inherit;
        padding-bottom: 10px;
      }
      /*#tab-second{*/
      /*    margin-left: 80px;*/
      /*}*/
    }
  }
}
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg: rgba(75, 160, 240, 1);
$dark_gray: #889aa4;
$light_gray: #eee;
.login-container {
  min-height: 690px;
  min-width: 990px;
  .login-center-layout{
    background: #409eff;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    position: absolute;
    top:110px;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 1px 5px 1px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .title {
    font-size: 26px;
    font-weight: 400;
    color: $light_gray;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .content {
    display: flex;
    .bg,
    .main {
      flex: 1;
    }
    .main {
      h3 {
        font-size: 20px;
        font-weight: 400;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #17181a;
        margin-top: 15px;
        text-align: center;
        height: 24px;
        line-height: 24px;
      }
      .login__tips{
        text-align: center;
        margin-top: 12px;
        color: #686a6c;
        font-size: 14px;
      }
    }
    .bg {
      height: 283px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}
.header {
  width: 100%;
  height: 60px;
  background: rgba(0, 0, 0, 0.9);
  .nav {
    margin: 0% auto;
    width: 1200px;
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 60px;
    position: relative;
    .logo {
      display: block;
      vertical-align: middle;
    }
    ul {
      list-style: none;
      li {
        float: left;
        /*line-height: 35px;*/
        font-weight: bold;
        &:not(&:last-child) {
          margin-right: 15px;
        }
        a {
          text-decoration: none;
          color: #999999;
          padding-left: 28px;
          font-size: 16px;
          /*border-left: 1px solid #ccc;*/
          cursor: pointer;
          > svg {
            margin-right: 2px;
          }
          &.router-link-active {
            color: #fff;
          }
          &:hover {
            color: #fff;
          }
        }
      }
    }
    .r-link {
      position: absolute;
      right: 0;
      margin: 0;
      li {
        a {
          padding-left: 14px;
        }
        a.login {
          border-right: 1px solid #ccc;
          padding-right: 15px;
        }
        a > svg {
          color: #999;
        }
        a.link,
        a.link > svg {
          /*color: #fff;*/
        }
      }
    }
    .location {
      color: #999;
      position: relative;
      top: 6px;
      a {
        border-left: none;
        font-size: 14px;
      }
    }
  }
}
.footer {
  position: absolute;
  bottom: 20px;
  .service-intro {
    width: 100%;
    margin-top: 30px;
    .servece-type {
      margin: 15px auto;
      height: 200px;
      width: 1200px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      .servece-type-info {
        color: #666666;
        ul {
          list-style: none;
          li {
            font-size: 14px;
            cursor: pointer;
            line-height: 26px;
            &:first-child {
              font-size: 16px;
              line-height: 28px;
              font-weight: bold;
            }
          }
        }
      }
    }
    .friend-link {
      display: flex;
      align-items: center;
      width: 1200px;
      margin: 0px auto;
      color: #666;
      .friend-link-item {
        margin: 0px auto;
        ul {
          list-style: none;
          li {
            padding: 5px 0px;
            text-align: center;
          }
        }
        .link-item {
          padding: 0px 8px;
          cursor: pointer;
        }
        .link-last-item {
          border: none;
        }
      }
    }
  }
  .copyright {
    width: 100%;
    color: #666;
    line-height: 30px;
    text-align: center;
    a {
      color: #232323;
      font-size: 20px;
    }
  }
  .contact-jx {
    flex-basis: 320px;
    .qr {
      > div {
        display: inline-block;
        &:first-child {
          margin-right: 80px;
        }
      }
    }
    p {
      width: 104px;
      text-align: center;
      margin: 0;
      margin-top: 10px;
    }
  }
}
.loginPic {
  padding: 0 10px;
  display: flex;
  span {
    &:first-child {
      margin-right: 10px;
    }
  }
  p {
    text-align: center;
    margin: 0;
    margin-bottom: 5px;
  }
}
</style>
